package com.cuit.lotery.controller;

import com.cuit.lotery.entity.Setting;
import com.cuit.lotery.service.SettingService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.ModelAndView;

import java.util.List;

@Controller
@RequestMapping("/setting")
public class SettingController {
    @Autowired
    SettingService service;

    @GetMapping("/")
    public ModelAndView index(){
        ModelAndView mv = new ModelAndView();
        mv.addObject("settings", getAll());
        mv.setViewName("setting");
        return mv;
    }
    @PostMapping("/update")
    @ResponseBody
    public boolean update(Setting setting){
        return service.update(setting);
    }
    @GetMapping("/getAll")
    @ResponseBody
    public List<Setting> getAll(){
        return service.getAll();
    }
}
